unit clsPedTabela;

interface

uses Dm, dbtables, biblio, Sysutils;

type
  TPedTabela = class(TObject)
  private
    Ped_numero: string;
  public
    Tab_codigo: string;
    Pedt_preco: Integer;
    Pedt_desc1: Double;
    Pedt_desc2: Double;
    Pedt_desc3: Double;
    Pedt_desc4: Double;
    Pedt_desc5: Double;
    Pedt_acrescimo: Double;
    Pedt_desc6: Double;
    Pedt_desc7: Double;
    Pedt_desc8: Double;
    Pedt_desc9: Double;
    Pedt_desc10: Double;
    function Gravar(p_Ped_numero: string): Byte;
    function Recuperar(P_ped_1, P_ped2: string): Byte;
    function Excluir(p_ped_1, P_ped_2: string): Byte;
  end;

implementation

function TPedTabela.Excluir(p_ped_1, P_ped_2: string): Byte;
var
  tq: TQuery;
begin
  tq := Tquery.Create(dmint);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tq.sql.Clear;
  tq.params.clear;
  tq.sql.add('DELETE FROM PedTabela WHERE Ped_numero=:K_Ped_1 or Ped_numero=:K_Ped_2');
  tq.ParamByName('k_Ped_1').AsString := strzero(P_Ped_1, 9);
  tq.ParamByName('k_Ped_2').AsString := strzero(P_Ped_2, 9);
  tq.execSQL;
  Result := 1;
  tq.close;
  tq.Free;
end;

function TPedTabela.Gravar;
var
  tq: TQuery;
begin
  tq := Tquery.Create(DmInt);
  tq.databasename := dmint.Db.DatabaseName;
  tq.active := False;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('SELECT * FROM PedTabela where Ped_numero=:k_Ped_numero');
  tq.ParamByName('k_Ped_numero').AsString := strzero(p_Ped_numero, 9);
  tq.open;
  if tq.eof then begin
    tq.sql.clear;
    tq.params.clear;
    tq.sql.add('INSERT INTO PedTabela VALUES(' +
      ':k_Ped_numero,' +
      ':k_Tab_codigo,' +
      ':k_Pedt_preco,' +
      ':k_Pedt_desc1,' +
      ':k_Pedt_desc2,' +
      ':k_Pedt_desc3,' +
      ':k_Pedt_desc4,' +
      ':k_Pedt_desc5,' +
      ':k_Pedt_acrescimo,' +
      ':k_Pedt_desc6,' +
      ':k_Pedt_desc7,' +
      ':k_Pedt_desc8,' +
      ':k_Pedt_desc9,' +
      ':k_Pedt_desc10)');
  end else begin
    tq.sql.clear;
    tq.params.clear;
    tq.sql.add('UPDATE PedTabela SET ' +
      'Tab_codigo       =:k_Tab_codigo,' +
      'Pedt_preco       =:k_Pedt_preco,' +
      'Pedt_desc1       =:k_Pedt_desc1,' +
      'Pedt_desc2       =:k_Pedt_desc2,' +
      'Pedt_desc3       =:k_Pedt_desc3,' +
      'Pedt_desc4       =:k_Pedt_desc4,' +
      'Pedt_desc5       =:k_Pedt_desc5,' +
      'Pedt_acrescimo   =:k_Pedt_acrescimo,' +
      'Pedt_desc6       =:k_Pedt_desc6,' +
      'Pedt_desc7       =:k_Pedt_desc7,' +
      'Pedt_desc8       =:k_Pedt_desc8,' +
      'Pedt_desc9       =:k_Pedt_desc9,' +
      'Pedt_desc10      =:k_Pedt_desc10 ' +
      'WHERE Ped_numero=:k_Ped_numero');
  end;
  tq.ParamByName('k_Ped_numero').AsString := strzero(p_Ped_numero, 9);
  tq.ParamByName('k_Tab_codigo').AsString := strzero(Tab_codigo, 3);
  tq.ParamByName('k_Pedt_preco').AsInteger := Pedt_preco;
  tq.ParamByName('k_Pedt_desc1').AsFloat := Pedt_desc1;
  tq.ParamByName('k_Pedt_desc2').AsFloat := Pedt_desc2;
  tq.ParamByName('k_Pedt_desc3').AsFloat := Pedt_desc3;
  tq.ParamByName('k_Pedt_desc4').AsFloat := Pedt_desc4;
  tq.ParamByName('k_Pedt_desc5').AsFloat := Pedt_desc5;
  tq.ParamByName('k_Pedt_acrescimo').AsFloat := Pedt_acrescimo;
  tq.ParamByName('k_Pedt_desc6').AsFloat := Pedt_desc6;
  tq.ParamByName('k_Pedt_desc7').AsFloat := Pedt_desc7;
  tq.ParamByName('k_Pedt_desc8').AsFloat := Pedt_desc8;
  tq.ParamByName('k_Pedt_desc9').AsFloat := Pedt_desc9;
  tq.ParamByName('k_Pedt_desc10').AsFloat := Pedt_desc10;
  tq.close;
  tq.execsql;
  result := 1;
  tq.Free;
end;

function TPedTabela.Recuperar(P_ped_1, P_ped2: string): Byte;
var
  tq: TQuery;
begin
  tq := Tquery.Create(dmint);
  tq.databasename := DmInt.Db.DatabaseName;
  tq.active := False;
  tq.sql.clear;
  tq.sql.add('SELECT * FROM PedTabela where Ped_numero=:K_Ped_1 or Ped_numero=:K_Ped_2');
  tq.Params[0].AsString := StrZero(P_ped_1, 9);
  tq.Params[1].AsString := StrZero(P_ped2, 9);
  tq.open;
  if tq.eof then result := 0 else result := 1;
  Ped_numero := tq.FieldByName('Ped_Numero').AsString;
  Tab_codigo := tq.FieldByName('Tab_codigo').AsString;
  Pedt_preco := tq.FieldByName('Pedt_preco').AsInteger;
  Pedt_desc1 := tq.FieldByName('Pedt_desc1').AsFloat;
  Pedt_desc2 := tq.FieldByName('Pedt_desc2').AsFloat;
  Pedt_desc3 := tq.FieldByName('Pedt_desc3').AsFloat;
  Pedt_desc4 := tq.FieldByName('Pedt_desc4').AsFloat;
  Pedt_desc5 := tq.FieldByName('Pedt_desc5').AsFloat;
  Pedt_acrescimo := tq.FieldByName('Pedt_acrescimo').AsFloat;
  Pedt_desc6 := tq.FieldByName('Pedt_desc6').AsFloat;
  Pedt_desc7 := tq.FieldByName('Pedt_desc7').AsFloat;
  Pedt_desc8 := tq.FieldByName('Pedt_desc8').AsFloat;
  Pedt_desc9 := tq.FieldByName('Pedt_desc9').AsFloat;
  Pedt_desc10 := tq.FieldByName('Pedt_desc10').AsFloat;
  tq.Close;
  tq.Free;
end;

end.

